package client.network;

import java.io.IOException;
import java.io.OutputStream;

import packages.Packages;

public class ClientOutgoingMessage extends Thread {

	private MessageMailBox messageMailBox;
	private OutputStream ostream;

	public ClientOutgoingMessage(OutputStream ostream,
			MessageMailBox messageMailBox) {
		this.messageMailBox = messageMailBox;
		this.ostream = ostream;
	}

	@Override
	public void run() {
		while (!interrupted()) {
			try {
				String message = messageMailBox.getOutgoingMessage();
				ostream.write(Packages.PACKAGE_CHAT_MESSAGE);
				ostream.write((message + '\n').getBytes());
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}

}
